home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Games of Daze
/
Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso
/
x2ftp
/
msdos
/
utils
/
2obj110
/
2obj.doc
< prev
next >
Wrap
Text File
|
1994-01-07
|
20KB
|
555 lines
2OBJ - Binary to OBJ File Converter.
====================================
Version 1.10
(c) 1993 Mark Thomas
NPS Software.
Contents.
=========
Description
Copyright and Licence
Using 2OBJ
Limitations
Release History
References
About the Author
Description.
============
2OBJ is a program that can create an object (.OBJ) file from binary
files so that they can be linked directly into a program along with
compiled source code and other data. It provides a smaller, faster
and more secure alternative to the traditional methods of including
data files in programs. Firstly 2OBJ eliminates the need for
external data files to accompany the main program, as all the data
can be included directly inside the final EXE file. It is faster
than the normal time consuming method of including binary files in
a program; translating it into source code as a large character
array which must then converted back into data by the compiler.
Features :
■ Decodes CEL, PCX, LBM and GIF files and their VGA palettes.
■ Generates OBJ file dependency information for MAKE utilities.
■ Splits files that are greater than 64k into multiple segments.
■ Full C source code is included.
Copyright and Licence.
======================
2OBJ is supplied for personal, private use. Feel free to
distribute the program as long as it is supplied in its original,
unmodified form, which includes this documentation.
You may NOT re-distribute modified versions of the source code nor
distribute the source code for a profit. If you make any
worthwhile changes to the source code, you can send them to me for
inclusion in a future release.
Since this software is free, it is supplied "AS IS", WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. It is supplied as is, in the hope
the people will find it useful.
Using 2OBJ.
===========
Usage:
2OBJ filetype [switches] infile [outfile[.OBJ | .BIN]] segspecs
filetype :
This character determines how 2OBJ treats the input file, it also
sets the input file extension default.
B : Binary, this of course can be any file, I have used 2OBJ for
such things as compressed help data, text files, sin tables,
ANSI screens, fonts, and MOD files.
C : AutoDesk Animator CEL files.
G : Compuserve GIF files.
L : DeluxePaint LBM files.
P : PCPaintbrush PCX files.
V VGA palette, 2OBJ can extract the palette from any of the graphic
file formats it supports.
switches :
/C Adds an underscore (_) to the symbol name.
Most PC C compilers add a leading underscore to all public
symbols (I cannot remember the reason why), this switch
provides an alternative to typing it directly.
/Hsize, /Tsize Removes a header/tail of size bytes from a binary
input file.
The header and tail functions allow the size of the binary file
to be adjusted. The size is an unsigned decimal long string.
/H[+|-] Include or exclude(default) the header of a graphics file.
By default 2OBJ will leave off the header of the graphics file
and write ONLY the compressed image data to the OBJ file. This
is because in most circumstances the size of the screen and
image will be constant and the information in the header is
unnecessary. With the header included the entire input file
will be included, the same result as if the binary file type
had been used.
/V Verbose mode, display extra information.
Mainly for debugging and checking, displays extra warning
messages and file statistics. For graphics files information
about the bitmap is displayed.
/L Convert all symbols to lowercase.
Counterpart to the /U switch but that is about all, totally
useless.
/S Split large (>64k) input files.
Multiple segments can be created to handle input files (or
decoded bitmaps) larger than the segment limit of 64k. These
(if linked together in the correct order) will recreate the
binary data in a contiguous region of memory. This is not to
be confused with 386 32 bit segments which can have a 4Gig
limit, 2OBJ does not support this in any way. 2OBJ will
produce up to 10 segments, so the maximum size of the input
file is 640k.
/U Convert all symbols to uppercase.
Pascal and Assembler (if none of the /Mx switches are used) are
case insensitive and convert all their symbols to uppercase.
By default 2OBJ will preserve the case of the symbols
characters as they are on the command line. In any case both
the /U and /L need never be used as the linker is normally
responsible for matching symbol names and will convert them as
necessary.
/X Disables output of .OBJ file when using /D.
This switch gives 2OBJ another utility purpose, it generates
the decoded bitmap that is normally the temporary 2OBJ decoding
file as a binary file containing the bitmap data. No OBJ file
is created.
/D Decode file type.
This switch forces 2OBJ to decode the graphics file or palette.
Note: 2OBJ simply decodes the files bitmap, so the output data
is dependant on how the file format organises the pixel data.
Generally all 256 colour files will produce the same output,
regardless of the file type.
GIFs use a byte for each pixel values. Each pixel in the image
has a byte value, no matter what number of colours there are.
So a decoded monochrome GIF will have width*height bytes
containing nothing more than 0 or 1 values. Decoding leaves
interleaved lines interleaved.
PCX files match the video memory organisation for the mode they
were created on, planar for mono and 16 colours and not for
256.
LBM files are interesting, the PC version of DeluxePaint has an
extension to the file format called PackedBitMap to handle the
fact that the VGA 256 colour mode is not planar (where as all
Amiga modes are). It is still possible to generate a 256
planar bitmap by saving the file with a stencil active, but
2OBJ will not be able to decode this properly. The output of a
decoded LBM is identical to PCX. 2OBJ cannot decode LBM files
when a mask defined, so the output for images saved in
DeluxePaint when a stencil was enabled or brushes will be
incorrect.
CELs are the simplest file format because, as far as I know,
they support only 256 colour images and have no compression.
The CEL file type can also be used to handle the temporary
".PIC" files AutoDesk Animator generates. The decode (/D)
option is superfluous with CELs because they are not compressed
or encoded.
The decode switch can also be used with palettes to convert
them to VGA colour register hardware values.
** Note: All formats except CELs store the palette as 8 bit **
** values which will not correctly work with the 6 bit VGA **
** hardware levels. Using the /D decode option 2OBJ will **
** scale down the values so they can be used directly. **
infile : Input file, the extension will default to
BIN/CEL/PCX/GIF/LBM to match the file type.
outfile : Output file, this is optional and will default to
infile.OBJ, or infile.BIN when the /X option is used.
segspecs : Segment specifications.
These are not required when the /X option is used. There are
two ways to specify a segment, the simplified model directive
or a complete assembler style segment definition.
[group:]SEGNAME:[align:]['class':]SYMBOL
align = [BYTE | WORD | PARA | PAGE]
The default group is none defined, the default alignment is
PARA and there is no default class string. All segments are
defined as public. There MUST be single quote (') characters
around the class string.
.model:SYMBOL
model = [TINY|SMALL|MEDIUM|COMPACT|LARGE|HUGE]
The .model generates a full segment specification as above.
The segment specifications generated are:
Group Name Align Class Combine
.TINY DGROUP _DATA WORD 'DATA' PUBLIC
.SMALL DGROUP _DATA WORD 'DATA' PUBLIC
.MEDIUM DGROUP _DATA WORD 'DATA' PUBLIC
.COMPACT name_DATA PARA 'DATA' PRIVATE
.LARGE name_DATA PARA 'DATA' PRIVATE
.HUGE name_DATA PARA 'DATA' PRIVATE
Where 'name' is the name of the input file.
Groups are used to collect several segments together into a
single segment and allows the data in those segments to be
accessed relative to the start of the group. The segments in
groups do not need to belong to the same class or have the same
combine type, however they must all fit within 64K.
The alignment tells the linker to ensure the segment begins on
the specified boundary. As the linker processes each new
segment when building the output EXE file it checks the
alignment type of the segment and if necessary will pad out the
difference with null bytes.
The segment class is a string which is used by the linker to
combine segments when building the output EXE file. The linker
will group together all PUBLIC segments with the same class
name.
The segment combine type is used by the linker whether two or
more segments should be combined into a larger segment.
PRIVATE segments will not be combined with any other segments
of the same name, while PUBLIC segments will be concatenated
with other segments of the same name and class to form a single
larger segment. 2OBJ does not allow the combine type to be set
and defines all segments as public. The exception is when 2OBJ
splits a large file, when it generates several private segments
64k in length.
There are several rules that linkers follow to combine
segments. Firstly only segments that have the public or common
type will be combined into a single larger segment. If a
segment has a public combine type, the linker automatically
combines it with other segments that have the same name and
belong to the same class. The resulting combined segment is
treated as if the smaller segments were defined in it as a
whole.
Link will normally place segments in the executable file in the
same order that it encounters them in the objects files.
When interfacing with a high level such as C or Pascal only the
simplified .model specifier should ever be needed. Assembler
allows either option to be used, depending on how the segments
are defined in the ASM source code.
If the data generated by 2OBJ seems to be incorrect there are
several ways to verify it, the best option is to use the /MAP
(or equivalent) option of your linker to generate a map file
which lists all segments and public symbols in the program.
Alternatively there are several shareware programs ReadOBJ or
OBJTool or commercially Borland's TDump which can provide a
descriptive dump of the OBJ file. Lastly a simple binary file
viewer can be used to check the names and the data in the OBJ
and EXE files. Typical problems are unexpected segment
combines made the linker, and segments exceeding the 64k limit.
The best solution to this is to give each segment you create
with 2OBJ a unique class name.
All error and warning messages generated by 2OBJ are self
explanatory.
Linking to languages.
=====================
These examples assume a 320x200x256 graphic file called testpic.XXX
is available in the current directory (where .XXX is the
appropriate file extension). The file type option in the 2OBJ
command line examples should be changed to match that of the file
type being used (in the examples I used a PCX file, filetype 'p').
The example programs also require a VGA, although the palette of
the graphic file is not displayed, so the colours will be
incorrect, unless the image uses the default VGA palette.
Assembler.
Tested with Tasm 3.0 and Masm 5.1
2OBJ p /d testpic _BITMAP_DATA:PARA:'BITMAP_DATA':Bitmap
link test.obj testpic.obj;
----
_BITMAP_DATA SEGMENT PARA PUBLIC 'BITMAP_DATA'
Extrn Bitmap:BYTE
_BITMAP_DATA ENDS
_CODE SEGMENT PARA PUBLIC 'CODE'
Main:
mov ax,0013h
int 10h
mov ax,_BITMAP_DATA
mov ds,ax
mov ax,0A000h
mov es,ax
xor di,di
mov si,di
mov cx,64000/2
rep movsw
mov ah,0
int 16h
mov ax,04C00h
int 21h
_CODE ENDS
END Main
----
C.
The OBJ file created by 2OBJ can be added in the command line of
the linker, if you are compiling from the command line. If you use
an IDE; in Turbo C, simply list the file in the project, with
Microsoft C and QuickC the OBJ file must be included in the MAK
file.
Tested with QuickC 2.0, requires Compact/Large/Huge memory model.
2OBJ p /d testpic .large:_Bitmap
----
extern char Bitmap[];
main()
{
_asm {
mov ax,0013h
int 10h
}
memcpy((char *)0xA0000000L, Bitmap, 64000);
getch();
_asm {
mov ax,0003h
int 10h
}
}
----
TurboPascal.
Pascal does not allow initialised data is to be defined within
object files, however it does allow procedures to be defined in OBJ
files. Although Bitmap is defined as a procedure you MUST NOT
execute it. It contains only data which must be referred to via
pointers.
Tested with TurboPascal 7.0
2OBJ p /d testpic CODE:WORD:Bitmap
----
uses crt;
{$L TESTPIC.OBJ }
procedure Bitmap; external;
begin
inline(
$B8/$13/$00/ (* mov ax,$0013 *)
$CD/$10 (* int $10 *)
);
Move (pointer(@Bitmap)^,ptr($A000,0)^,64000);
ReadKey;
inline(
$B8/$03/$00/ (* mov ax,$0013 *)
$CD/$10 (* int $10 *)
);
end.
----
QuickBasic
It is apparently also possible to use OBJ files with QuickBasic in
a manner similar to that required with Pascal, but I have no idea
how this is done.
Limitations.
============
None of the graphics file formats are totally supported (although
most of the exceptions are not in common use) :
■ Cannot properly decode LBM files that have a mask (stencil)
defined unfortunately this includes brush files saved by
DeluxePaint.
■ It is unlikely that 2OBJ can handle LBM files that were created
on an Amiga.
■ Does not support GIF files with multiple images or extensions
blocks.
■ Support for 24 bit variations of GIF or PCX is untested.
■ CEL support is based only on viewing CEL files with a file
editor.
[2OBJ has been tested with files from DeluxePaint II Enhanced,
Autodesk Animator, Windows 3.1 Paint and Improces 4.0]
Release History.
================
1.00 21-05-92 Originally two programs; PCX2OBJ and BIN2OBJ written to
support a loader, these sat on my hd for a while
undergoing various changes when I required them and
eventually evolved into 2OBJ.
1.10 08-12-93 First public release.
References.
===========
■ MS-DOS Encyclopedia, MS Publishing
Provides a detailed specification of the OBJ file format.
■ WASP 2.00b Source by Steven Reiz.
An Amiga graphic file conversion program, the basis for LBM support.
■ GIF source by Steven A. Bennett
About the Author.
=================
■ Mark Thomas is a 21 year old graduate in Information Technology
and is currently seeking employment [subtle hint to prospective
employers].
■ Member of the Sivris demo group who have recently released our
first demo 'Divide by Zero' and are now starting our second
'Information Generation'.
■ Member of NPS Internationalé who are not doing much at all at the
moment.
■ Author of the "soon to be released" MegaDebugger [MMD], see the
advert at the end of this file.
I would appreciate any comments/suggestions you may wish to make
about 2OBJ. Also if you make any significant modifications to the
source I would like to receive them to be incorporated in the next
release (particularly more file formats). I myself have no
particular plans for 2OBJ at the moment, as it is working quite
well for my purposes. You are welcome to use any my routines in
your own programs as long as there is some credit/mention made to
their original author.
FidoNet:
3:640/450
BBS:
The Farmer's BBS
+61 76 916258
No Net Address:
Mark Thomas
8 Herronbee Street
Toowoomba, Queensland
Australia 4350.
InterNet:
I wish!
┌─────────────────────────────────────────────────────────────────┐
│ <MMD> Mark's MegaDebugger. Full screen debugger for the 80x86. │
│─────────────────────────────────────────────────────────────────│
│ │
│ Features: │
│ ■ Register level screen swapping: saves and restores "mode-x", │
│ screens, split screens, palettes and screen memory perfectly.│
│ ■ C, Pascal, Assembler and A86 expression support. │
│ ■ Windowed display with EGA/VGA 25, 28, 43 and 50 line support. │
│ ■ Conditional breakpoints and watchpoints (global breakpoints). │
│ ■ Displays memory allocation, open files and interrupt usage. │
│ ■ Keyboard keeper, can always detect break-key presses. │
│ ■ Completely configurable (keys, colours, options). │
│ ■ Online context sensitive help. │
│ ■ Uses only 20k-50k memory. │
└─────────────────────────────────────────────────────────────────┘
-end-